<?php

class Template
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    /**
     * @var string
     */
   
    public function __construct()
    {
			$this->_db = Zend_Registry::get('db');
    }
    
    public function listTemplates()
    {
    	$getTemplates = $this->_db->fetchAll("
			SELECT template_id,template_title,template_content,is_default,module_name
			FROM templates 
			
		");
		
		return $getTemplates;
	}
 public function listTemplatesfornewsletter()
    {
    	$sql="select  template_id,template_title from templates ";
    	//echo $sql;exit;
    	$options = $this->_db->fetchPairs($sql);
	//	print_r($options);exit;
		return $options;
	}

    public function getTemplate($template_id)
    {
    //	echo $newsletter_id;exit;
    	$geTemplatedetails = $this->_db->fetchrow("
			select  template_id,template_title, template_content,module_name,is_default
			from templates where  template_id='".$template_id."'
			
		");
		//print_r($getNewsletterdetails);
		return $geTemplatedetails;
       
    }
    
public function getTemplatenewsletter($template_id)
    {
    //	echo $newsletter_id;exit;
    	$geTemplatedetails = $this->_db->fetchrow("
			select  template_content from templates where  template_id='".$template_id."'
			
		");
		//print_r($getNewsletterdetails);
		return $geTemplatedetails;
       
    }

    public function addTemplate($template_title,  $template_content,$module_name,$is_default)
    {
         
      $addTemplates = $this->_db->exec("
      insert into templates (template_title,template_content,module_name,is_default) 
      values ('".$template_title."','".$template_content."','".$module_name."',".$is_default.")
	  ");
    	/*$command="call proc_newsletter('ADD','".$newsletter_title."','".$newsletter_content."',".$template_id.",".$newsletter_id.",1)";
        echo  $command;exit;
		$addTemplates = $this->_db->exec($command);*/
		return $addTemplates;
    }

    public function updateTemplate($template_id, $template_title, $template_content,$module_name,$is_default)
    {
    	
		
      $UpdateTemplate = $this->_db->exec("
      update  templates set template_title='".$template_title."' ,template_content='".$template_content."',module_name='".$module_name."',is_default=".$is_default." 
       WHERE template_id=".$template_id."
		");
    	/*$command="call proc_newsletter('EDIT','".$newsletter_title."','".$newsletter_content."',".$template_id.",".$newsletter_id.",1)";
    	//echo  $command;exit;
		$EditTemplates = $this->_db->exec($command);*/
		return $UpdateTemplate;
        
    }

    public function deleteTemplate($template_id)
    {
    	$command="delete from templates where template_id=".$template_id."";
     //   echo $command;exit;
       $DeleteTemplates = $this->_db->exec($command);
      
		return $DeleteTemplates;
        
    }

}

